<div class="open-form">
  <div class="open-model">
    <div class="open-auto">
      <button class="layui-btn" id="isCheckFun" style="border-radius: 4px;margin-bottom: 10px">添加计价区间</button>
      <table id="warehouseProductBrandForm"></table>
    </div>
    <div class="layui-form-item text-right">
      <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
    </div>
  </div>
</div>
<!-- 表单弹窗 -->
<script type="text/html" id="warehouseProductMarkPricingForm">
  <form lay-filter="warehouseProductMarkPricingForm" id="warehouseProductMarkPricingFormCss" class="layui-form open-form">
    <input name="markId" type="hidden"/>
    <div class="open-model">
      <div class="open-auto">
        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>牌号名称</label>
            <div class="layui-input-block">
              <input id="markName" name="markName" placeholder="请输入牌号名称" type="text" class="layui-input" maxlength="200" disabled autocomplete="off"/>
            </div>
          </div>
        </div>
        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>加工工艺</label>
            <div class="layui-input-block">
              <select id="processId" name="processId" lay-filter="processId"  lay-search lay-verify="required" required></select>
            </div>
          </div>
        </div>
        <div class="layui-col-xs6">
        <div class="layui-form-item">
          <label class="layui-form-label"><span style="color: red">*</span>属性分类</label>
          <div class="layui-input-block">
            <select name="type" lay-filter="type" lay-verify="required" required>
              <option value="">请选择</option>
              <option value="1">厚度</option>
              <option value="2">长度</option>
              <option value="3">包装</option>
            </select>
          </div>
        </div>
      </div>

        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>编号</label>
            <div class="layui-input-block">
              <input id="code" name="code" placeholder="请输入编码" type="text" class="layui-input" maxlength="200" lay-verify="required" required autocomplete="off"/>
            </div>
          </div>
        </div>

        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>上阈值</label>
            <div class="layui-input-block">
              <input id="upperThreshold" name="upperThreshold" placeholder="请输入上阈值" type="text" lay-verify="required" required class="layui-input" maxlength="200" autocomplete="off"/>
            </div>
          </div>
        </div>
        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>下阈值</label>
            <div class="layui-input-block">
              <input id="lowerThreshold" name="lowerThreshold" placeholder="请输入下阈值" type="text" lay-verify="required" required class="layui-input" maxlength="200" autocomplete="off"/>
            </div>
          </div>
        </div>
        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>描述</label>
            <div class="layui-input-block">
              <input id="description" name="description" placeholder="请输入描述" type="text"  lay-verify="required" required class="layui-input" maxlength="200" autocomplete="off"/>
            </div>
          </div>
        </div>
        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>单价(元/吨)</label>
            <div class="layui-input-block">
              <input id="unitPrice" name="unitPrice" placeholder="单价" type="text" maxlength="200" class="layui-input" lay-verify="required" required autocomplete="off"/>
            </div>
          </div>
        </div>
        <div class="layui-col-xs6">
          <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>排序</label>
            <div class="layui-input-block">
              <input id="sortOrder" name="sortOrder" placeholder="排序" type="text" maxlength="200" class="layui-input" lay-verify="required" required autocomplete="off"/>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="warehouseFormSubmit" lay-submit>保存</button>
      </div>
    </div>
  </form>
</script>
<script>
  layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl'], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    const nowData = {...parentData}
    let data = nowData?.data;
    console.log(nowData,"11111")
    let cacheList = nowData.cacheList
    table.render({
      elem: '#warehouseProductBrandForm',
      url: config.base + `warehouse/warehouse/admin/productMark/priceList`,
      where: {markId:data.id,notInListIds: nowData.notInListIds},
      page: true,
      cellMinWidth: 100,
      cols: [[
        {type: 'numbers', title: '序号'},
        {field: 'code', align: 'center', title: '属性编号', width: 150},
        {field: 'label_name', align: 'center', title: '加工工艺', width: 150}
        , {field: 'upper_threshold', align: 'center', title: '上阈值', width: 150}
        , {field: 'lower_threshold', align: 'center', title: '下阈值', width: 150}
        , {field: 'type', align: 'center', title: '属性分类',
          templet: function (d) {
            return d.type === '1' ? "厚度" : d.type ==='2' ? "长度" :  "包装"
          }}
        , {field: 'unit_price', align: 'center', title: '单价'}
        , {field: 'description', align: 'center', title: '描述'}
        ,{field: 'is_deleted', align: 'center', title: '状态',templet: d => d.is_deleted ? '禁用' : '正常',}
      ]]
    });
    $('#isCheckFun').click(() => {
      let obj={markName:data.markName,markId:data.id}
        openForm(obj)
    })
    function openForm(data){
      let addPriceForm=admin.open({
        type: 1,
        area: '900px',
        offset: '120px',
        title: '添加计价区间',
        content: $('#warehouseProductMarkPricingForm').html(),
        success: async function () {
          admin.initDataSelect("enterprise/dict/admin/dictLabel/list", {limit: 9999,dictType: "warehouse_processingType"}, "processId", data ? data.processId : null, "加工工艺", 'labelName', null);

          form.val('warehouseProductMarkPricingForm', data);
          // 表单提交事件
          form.on('submit(warehouseFormSubmit)', function (d) {
            layer.load(2);
            admin.req('warehouse/warehouse/admin/productMark/addPrice', JSON.stringify(d.field), function (res) {
              layer.closeAll('loading');
              if (res.code == 200) {
                layer.msg(res.msg, {icon: 1});
                table.reload('warehouseProductBrandForm');
                layer.close(addPriceForm)
              } else {
                layer.msg(res.msg, {icon: 2});
              }
            }, 'POST',true,"application/json;charset=utf-8");
            return false;
          });
          if (data != undefined) {
            var picture = data.picture;
            if (picture) {
              $("#pictureDiv").html('<img src="' + picture + '" alt="上传成功后渲染" style="max-width: 196px"><input type="hidden" name="picture" value="' + picture + '">');
            }
            form.val('warehouseForm', data);
          }

        }
      });
    }

  })
</script>